package net.csdn.business.webhook.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.common.annotation.Inner;
import net.csdn.business.common.domain.query.WebhookLogQuery;
import net.csdn.business.common.domain.vo.WebHookEvent;
import net.csdn.business.common.domain.vo.WebhookLogVO;
import net.csdn.business.webhook.service.IWebhookLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * @ClassName WebhookLogController
 * @Description webhook通知日志Controller
 * @Author zhangyl
 * @Date 2023/4/23 17:11
 */
@Inner
@RestController
@RequestMapping("/api/v1/webhook/log")
public class WebhookLogController
{
    @Autowired
    private IWebhookLogService webhookLogService;

    /**
     * 分页查询webhook通知日志列表
     */
    @PostMapping("/list")
    public Page<WebhookLogVO> findPageList(@RequestBody @Validated WebhookLogQuery query)
    {
        return webhookLogService.findPageList(query);
    }

    /**
     * 根据id获取webhook通知日志详细信息
     */
    @GetMapping(value = "/{id}")
    public WebhookLogVO getInfo(@PathVariable("id") String id)
    {
        return webhookLogService.selectWebhookLogById(id);
    }

    /**
     * 查询最近一次请求的状态
     */
    @GetMapping("/lastDelivery/{webhookId}")
    public Map<String,Object> getLastDelivery(@PathVariable("webhookId")String webhookId){
        return webhookLogService.getLastDelivery(webhookId);
    }
}
